/**
 * Description:
 * Class Name:ReadTeacher
 * Date:2022/5/2 19:01
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第15章_输入输出._15_8_Java9改进的对象序列化._15_8_3_对象引用的序列化;

import 疯狂Java讲义.第15章_输入输出._15_8_Java9改进的对象序列化._15_8_2_使用对象流实现序列化.Person;

import java.io.FileInputStream;
import java.io.ObjectInputStream;

public class ReadTeacher {
    public static void main(String[] args) {
        try (
                var ois = new ObjectInputStream(new FileInputStream("Chapter_15_8_teacher.txt"))
                ){
            // 需要依次读取输入流中的4个对象
            var t1 = (Teacher)ois.readObject();
            var t2 = (Teacher)ois.readObject();
            var per = (Person)ois.readObject();
            var t3 = (Teacher)ois.readObject();

            System.out.println("t1的student引用和per是否相同：" + (t1.getStudent() == per));
            System.out.println("t2的student引用和per是否相同：" + (t2.getStudent() == per));
            System.out.println("t2和t3是否引用的是同一个对象：" + (t2 == t3));
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }
}
//t1的student引用和per是否相同：true
//t2的student引用和per是否相同：true
//t2和t3是否引用的是同一个对象：true